﻿CREATE PROCEDURE [dbo].[AAA]
AS
BEGIN
/*
ДИАПАЗОНЫ КОДОВ ВОЗВРАТА ПРОЦЕДУР ПРОВЕРОК
По пользователям : 100 - 199
По товарам : 200 - 299
По контрагентам : 300 - 399
По документам : 400 - 499
По кассам : 500 - 599
По партиям : 600 - 699
*/

	SET NOCOUNT ON;
/*
SELECT G.FullName, P.GoodsId , P.Id AS PartyId, P.RestQntty, L.LineSum FROM CD.Parties P INNER JOIN (
select PartyId, Sum(Qntty) AS LineSum FROM CA.GoodsDocLines
GROUP BY PartyId ) L ON P.Id = L.PartyId 
INNER JOIN dbo.vwGoodsDetailed G ON P.GoodsId = G.Id
WHERE P.RestQntty <> L.LineSum

UPDATE R SET R.RestQntty = T.LineSum,
R.MD = getdate(), R.MW = suser_sname()
FROM CD.Parties AS R INNER JOIN (
SELECT PartyId, Sum(Qntty) AS LineSum FROM CA.GoodsDocLines
GROUP BY PartyId
) AS T ON R.Id = T.PartyId
WHERE R.RestQntty <> T.LineSum

select * from dbo.vwInputLines where partyid = -59301

select * from CA.GoodsDocLines where partyid = -59298


SELECT * FROM fn_trace_getinfo ( 0 )

SELECT * FROM sys.configurations ORDER BY name ;

sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
sp_configure 'default trace enabled', 0;
GO
RECONFIGURE;
GO


SELECT *  FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=c:\dic.xls', 'SELECT * FROM [Assortment$]')
WHERE MedFormId Is Null

UPDATE A SET A.MedFormId = S.MedFormId, A.GNVLS = S.GNVLS
FROM CA.Assortment A INNER JOIN OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=c:\dic.xls', 'SELECT * FROM [Assortment$]') AS S
ON A.Id = S.Id
WHERE A.MedFormId <> S.MedFormId OR A.GNVLS <> S.GNVLS

--несоответствие розничных сумм розничной цене 

SELECT L.DocId, L.RetailSum, L.Qntty * P.RetailPrice AS CalcSum
FROM CA.GoodsDocLines AS L INNER JOIN CD.Parties AS P 
ON L.PartyId = P.Id AND L.RetailSum <> L.Qntty * P.RetailPrice
*/


	return 0
END





